package dhm.com.dhmshop.adapter.home;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import dhm.com.dhmshop.R;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.entity.LogisticsBean;
import dhm.com.dhmshop.framework.module.home.entity.ListHotGoodsEntity;

/**
 * Created by admin
 * 2019/4/29
 * 所有订单适配器
 */
public class LogisticsAdapter extends RecyclerView.Adapter<LogisticsAdapter.ViewHolder> {

    private LogisticsBean.DataBeanX shopList;
    private Context context;


    public LogisticsAdapter(Context context) {
        this.shopList = new LogisticsBean.DataBeanX();
        this.context = context;
    }


    public void setShopList(LogisticsBean.DataBeanX shopList) {
        this.shopList = shopList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ViewHolder viewHolder;
        View view = LayoutInflater.from(context).inflate(R.layout.item_logistics, viewGroup, false);
        viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
        viewHolder.context.setText(shopList.getData().get(i).getContext());
        if (i == 0) {
            switch (shopList.getState()) {
                case "0":
                    viewHolder.status.setText("在途");
                    break;
                case "1":
                    viewHolder.status.setText("揽件");
                    break;
                case "2":
                    viewHolder.status.setText("疑难");
                    break;
                case "3":
                    viewHolder.status.setText("签收");
                    break;
                case "4":
                    viewHolder.status.setText("退签");
                    break;
                case "5":
                    viewHolder.status.setText("派件");
                    break;
                case "6":
                    viewHolder.status.setText("退回");
                    break;
                default:
            }
            viewHolder.linetop.setVisibility(View.GONE);
        }else {
            viewHolder.status.setText(shopList.getData().get(i).getLocation());
        }
        if (i == shopList.getData().size() - 1) {
            viewHolder.linebottom.setVisibility(View.GONE);
        }
        try {
            String datemonthStr = new SimpleDateFormat("MM-dd").format(new SimpleDateFormat("MM-dd").parse(shopList.getData().get(i).getTime()));
            viewHolder.month.setText(datemonthStr);
            String datetimeStr = new SimpleDateFormat("hh:mm").format(new SimpleDateFormat("hh:mm").parse(shopList.getData().get(i).getTime()));
            viewHolder.time.setText(datetimeStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }

//        viewHolder.check.onTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_UP,0,0,0));

    }

    @Override
    public int getItemCount() {
        if (shopList.getData()==null){
            return 0;
        }
        return shopList.getData().size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public TextView month;
        public TextView time;
        public TextView linetop;
        public TextView linebottom;
        public TextView status;
        public TextView context;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            month = itemView.findViewById(R.id.month);
            time = itemView.findViewById(R.id.time);
            linebottom = itemView.findViewById(R.id.linebottom);
            linetop = itemView.findViewById(R.id.linetop);
            status = itemView.findViewById(R.id.status);
            context = itemView.findViewById(R.id.context);
        }
    }

    private OnClick onClick;

    public void setdeleteClick(OnClick onClick) {
        this.onClick = onClick;
    }

    public interface OnClick {
        void item(int posttion, boolean checked);
    }

    private OnIntentClick onIntentClick;

    public void setaddClick(OnIntentClick onClick) {
        this.onIntentClick = onClick;
    }

    public interface OnIntentClick {
        void item(int posttion, int num);
    }

    private OnShopClick onshopClick;

    public void setaddClick(OnShopClick onClick) {
        this.onshopClick = onClick;
    }

    public interface OnShopClick {
        void item(int posttion);
    }


}

